<%--
  Created by IntelliJ IDEA.
  User: Gavin
  Date: 2016/2/5
  Time: 11:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<head>
    <base href="<%=basePath%>">
    <title>注册</title>
    <script src="static/javascript/jquery-1.11.3.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {

            $("#registerSubmit").click(function () {
                var map = {
                    "用户名": $("#userName"),
                    "密码": $("#userPassword"),
                    "再次输入密码": $("#userPasswordAgain"),
                    "性别": $("#sex"),
                    "手机号": $("#mobilePhoneNo"),
                    "邮箱": $("#email")
                }
                if($.judgeNotNull(map) == false){
                    return false;
                }
                if($("#userPassword").val() != $("#userPasswordAgain").val()) {
                    alert("两次密码输入不一致！");
                    return;
                }
                $.ajax({
                    type : 'get',
                    contentType:"application/json;charset=utf-8",
                    url : 'user/registerAction',
                    dataType : 'json',
                    cache: false,
                    timeout: 5000,
                    async: false,
                    data: {
                        "userName": encodeURI($("#userName").val()),
                        "userPassword": encodeURI($("#userPassword").val()),
                        "sex": encodeURI($("#sex").val()),
                        "mobilePhoneNo": encodeURI($("#mobilePhoneNo").val()),
                        "email": encodeURI($("#email").val())
                    },
                    success: function(result){
                        alert(result);
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        alert("ajax异常，请联系管理员！");
                    }
                });
            });
        });
    </script>
</head>
<body>
<div class="container">
    <div>
        <table>
            <tr>
                <th>用户名：</th>
                <td><input type="text" id="userName" name="userName"/></td>
            </tr>
            <tr>
                <th>密码：</th>
                <td><input type="password" id="userPassword" name="userPassword"/></td>
            </tr>
            <tr>
                <th>再次输入密码：</th>
                <td><input type="password" id="userPasswordAgain" name="userPasswordAgain"/></td>
            </tr>
            <tr>
                <th>性别：</th>
                <td><input name="sex" id="sex" type="radio" checked="true" value="男"/>男 <input name="sex" type="radio" value="女"/>女</td>
            </tr>
            <tr>
                <th>手机号：</th>
                <td><input type="text" id="mobilePhoneNo" name="mobilePhoneNo" /></td>
            </tr>
            <tr>
                <th>邮箱: </th>
                <td><input type="text" id="email" name="email" /></td>
            </tr>
            <tr>
                <th></th>
                <td><button name="submit" id="registerSubmit">注册</button></td>
            </tr>
        </table>

    </div>
</div>
</body>
</html>
